let reg = new Vue({
    el: "#reg",
    data: {
        username: '',
        email: '',
        password: '',
        confirm: '',
        message: '',
        hasError: false
    },
    methods: {
        register: function () {
            let form = new FormData();
            form.append("username", this.username);
            form.append("email", this.email);
            form.append("password", this.password);
            form.append("confirms", this.confirm);
            console.log(form);
            if (this.password != this.confirm) {
                this.message = "密码与确认密码不一致！";
                this.hasError = true;
                return;
            }
            axios({
                method: 'post',
                url: '/register',
                data: form
            })
                .then(function (response) {
                    if (response.data == "注册完成") {
                        reg.hasError = false;
                        location.href = "/pages/prebuilt-pages/default-login.html?register";
                    } else {
                        console.log(response.data);
                        reg.hasError = true;
                        reg.message = response.data;
                    }
                });
        }
    }
});